<template>
    <div>
        <basic-container>
            <avue-crud :option="optionTradeLog" :data="dataTradeLog" ref="tradeLogList" v-model="formTradeLog" :table-loading="tradeLogLoading"
                       :page="tradeLogPage" @refresh-change="refreshTradeLogListChange" @search-change="searchTradeLogListChange"
                       @search-reset="searchTradeLogListReset" @current-change="currentTradeLogListChange" @size-change="sizeTradeLogListChange">
            </avue-crud>
        </basic-container>
    </div>
</template>
<script>
    import {
        tradeRecordLogList
    } from '@/api/account/seller/userAccount';
    import {
        getList,
        getIntegralList
    } from '@/api/account/userAccountLog/userAccountLog';
    export default {
        name: 'userAccount',
        props: ["whichRole","whichType", "passUaId","passTrId","userType"],
        data() {
            return {
                optionTradeLog: {
                    size: 'mini',
                    menu: false,
                    columnBtn:false,
                    addBtn:false,
                    border: true,
                    rowKey: 'id',
                    align:'center',
                    height: 'auto',
                    // calcHeight: 380,
                    column: [
                        {
                            label: "创建时间",
                            prop: "addTime",
							widyh:160,
                            fixed: true,
                        },
                        {
                            label: "操作金额",
                            prop: "amount",
                            fixed: true,
							widyh:80,
                            hide:false,
                        },
                        {
                            label: "操作积分",
                            prop: "integral",
                            fixed: true,
                            hide:false,
                        },
                        {
                            label: "日志描述",
                            prop: "content",
                            fixed: true,
                        },
                        {
                            label: "交给平台的抽佣金额",
                            prop: "serviceAmount",
                            fixed: true,
                            hide:false,
                        },
                    ]
                },
                dataTradeLog:[],
                formTradeLog:{},
                tradeLogLoading:false,
                tradeLogPage: {
                    pageSize: 10,
                    currentPage: 1,
                    total: 0
                },
                tradeRecordLogQuery: {},
            }
        },
        created() {
            console.log(this.whichRole);
            this.tradeRecordLogQuery.uaId = this.passUaId;
            this.tradeRecordLogQuery.trId = this.passTrId;
            this.tradeLogPage.currentPage = 1;
            if(this.whichType == "original"){
                this.optionTradeLog.column[1].hide = false;
                this.optionTradeLog.column[2].hide = true;
                this.optionTradeLog.column[4].hide = false;
            }
            else if(this.whichType == "integral"){
                this.optionTradeLog.column[1].hide = true;
                this.optionTradeLog.column[2].hide = false;
                this.optionTradeLog.column[4].hide = true;
            }

            if(this.userType == "userType"){
                this.optionTradeLog.column[4].hide = true;
            }
            else if(this.userType == "sellerType"){
                this.optionTradeLog.column[4].hide = false;
            }

            this.onTradeRecordLogListLoad(this.tradeLogPage);
        },
        methods: {
            onTradeRecordLogListLoad(tradeLogPage, params = {},done){
                if(this.whichType == "original" && this.whichRole == "seller"){
                    tradeRecordLogList(tradeLogPage.currentPage, tradeLogPage.pageSize, Object.assign(params, this.tradeRecordLogQuery)).then(res=>{
                        if(done){
                            done();
                        }
                        if(res.data.code==200){
                            const dataTradeLog = res.data;
                            this.tradeLogPage.total = dataTradeLog.count;
                            this.dataTradeLog=res.data.data
                        }else{
                            this.$message(res.data.message)
                        }
                    })
                }
                else if(this.whichType == "original" && this.whichRole == "PC"){
                    getList(tradeLogPage.currentPage, tradeLogPage.pageSize, Object.assign(params, this.tradeRecordLogQuery)).then(res=>{
                        if(done){
                            done();
                        }
                        if(res.data.code==200){
                            const dataTradeLog = res.data;
                            this.tradeLogPage.total = dataTradeLog.count;
                            this.dataTradeLog=res.data.data
                        }else{
                            this.$message(res.data.message)
                        }
                    })
                }
                else if(this.whichType == "integral"){
                    getIntegralList(tradeLogPage.currentPage, tradeLogPage.pageSize, Object.assign(params, this.tradeRecordLogQuery)).then(res=>{
                        if(done){
                            done();
                        }
                        if(res.data.code==200){
                            const dataTradeLog = res.data;
                            this.tradeLogPage.total = dataTradeLog.count;
                            this.dataTradeLog=res.data.data
                        }else{
                            this.$message(res.data.message)
                        }
                    })
                }

            },
            refreshTradeLogListChange(){
                this.currentTradeLogListChange(1);
                this.onTradeRecordLogListLoad(this.tradeLogPage);
            },
            searchTradeLogListChange(params,done){
                this.tradeRecordLogQuery = params;
                this.onTradeRecordLogListLoad(this.tradeRecordLogQuery, params,done);
            },
            searchTradeLogListReset(){
                this.tradeRecordLogQuery = {};
                this.onTradeRecordLogListLoad(this.tradeLogPage);
            },
            currentTradeLogListChange(currentPage){
                this.tradeLogPage.currentPage = currentPage;
                this.onTradeRecordLogListLoad(this.tradeLogPage);
            },
            sizeTradeLogListChange(pageSize){
                this.tradeLogPage.pageSize = pageSize;
                this.onTradeRecordIntegralListLoad(this.tradeLogPage);
            },
        },

    }
</script>
<style scoped="scoped" lang="scss">
</style>
